package com.kkwrite.regimen.provider.controller.apply;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kkwrite.regimen.common.entity.dto.OutDTO;
import com.kkwrite.regimen.common.entity.dto.apply.ApplyJoinInDTO;
import com.kkwrite.regimen.provider.exception.ServiceException;
import com.kkwrite.regimen.provider.service.join.JoinService;
import com.kkwrite.regimen.provider.service.join.JoinServiceImpl;

/**
 * 申请加盟服务
 * 
 * @author Ke.Wang
 * @date 2018年7月17日 上午8:20:23
 */
@RestController
@RequestMapping("/join")
public class JoinController {

	private static final Logger logger = LoggerFactory.getLogger(JoinServiceImpl.class);
	
	@Resource(name = "joinService")
	private JoinService joinService;
	
	@PostMapping("/apply")
	public OutDTO<Object> apply(@RequestBody ApplyJoinInDTO applyJoinInDTO) {
		OutDTO<Object> outDTO = new OutDTO<Object>();
		try {
			joinService.saveApply(applyJoinInDTO);
			outDTO.setSuccess("true");
			outDTO.setMsg("");
		} catch (ServiceException e) {
			e.printStackTrace();
			logger.error("申请加盟失败！applyJoinInDTO = " + applyJoinInDTO + "_" + e.getMessage());
			outDTO.setSuccess("true");
			outDTO.setMsg(e.getMessage());
		}
		return outDTO;
	}
	
}
